package com.xiao.train.member.controller;

import com.xiao.train.common.resp.CommonResp;
import com.xiao.train.common.resp.MemberLoginResp;
import com.xiao.train.member.enums.PassengerTypeEnum;
import com.xiao.train.member.req.MemberLoginReq;
import com.xiao.train.member.req.MemberRegisterReq;
import com.xiao.train.member.req.MemberSendCodeReq;
import com.xiao.train.member.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("member")
public class MemberController {
    @Autowired
    MemberService memberService;

    @GetMapping("count")
    public CommonResp count() {
        String code = PassengerTypeEnum.ADULT.getCode();
        return new CommonResp(memberService.count());
    }

    @PostMapping("register")
    public CommonResp register(@Valid @RequestBody MemberRegisterReq req) {
        return new CommonResp(memberService.register(req));
    }

    @PostMapping("send-code")
    public CommonResp sendCode(@Valid @RequestBody MemberSendCodeReq req) {
        memberService.sendCode(req);
        return new CommonResp();
    }

    @PostMapping("login")
    public CommonResp login(@Valid @RequestBody MemberLoginReq req) {
        return new CommonResp(memberService.login(req));
    }
}
